package com.cs.study.homework._0318;

import lombok.Data;

import java.util.Arrays;
import java.util.HashMap;

public class Demo {
    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 4, 5};
        Solution solution = new Solution();
        int[] result = solution.getResult(nums,3);
        System.out.println(Arrays.toString(result));

    }
}

@Data
class Solution{

    public int[] getResult(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        //依次放入比target小的值
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] < target) {
                map.put(i, nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            //计算差值一一比较
            int target1 = target - nums[i];
            if (map.containsKey(target1) && map.get(target1) != i) {
                return new int[]{i, map.get(target1)};
            }
        }
        return null;
    }

}

